<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="https://cdn.jsdelivr.net/npm/poll-api@1.0.6"></script>
  <script>
    const fn = (err, res) => {
      if (err) {
        console.log(err, 'fn1')
        return
      }
      console.log(res.data, 'fn1')
    }

    const fn2 = (err, res) => {
      if (err) {
        console.log(err, 'fn2')
        return
      }
      console.log(res.data, 'fn2')
    }

    // const source = axios.CancelToken.source()

    // 开启轮询
    $pollApi.poll('test', fn, {
      pollInterval: 5, // 轮询间隔时间
      pollCount: 3, // 轮询次数, 如果是 -1 则一致轮询
      delay: 0, // 延迟几秒后触发轮询
      axiosInstance: null, // axios 实例
      requestConfig: {
        url: 'https://api.jisuapi.com/area/province',
        // cancelToken: source.token
      }
    })

    $pollApi.poll('test1', fn2, {
      pollInterval: 5, // 轮询间隔时间
      pollCount: 3, // 轮询次数, 如果是 -1 则一致轮询
      delay: 0, // 延迟几秒后触发轮询
      axiosInstance: null, // axios 实例
      requestConfig: {
        url: 'https://api.jisuapi.com/area/province',
        // cancelToken: source.token
      }
    })


    setTimeout(() => {
      $pollApi.destroy()
    }, 5 * 1000)
  </script>
</body>
</html>